package com.im.service.config;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.License;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.Arrays;
import java.util.List;

@Configuration //声明该类为配置类
@EnableSwagger2 //声明启动Swagger2
public class SwaggerConfig {

    @Bean
    public Docket customDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .globalOperationParameters(globalOperationParameters())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("im-service")//文档说明
                .version("1.0.0")//文档版本说明
                .build();
    }

    private List<Parameter> globalOperationParameters() {
        return Arrays.asList(
                new ParameterBuilder()
                        .name("userSign")
                        .description("用户签名")
                        .modelRef(new ModelRef("string"))
                        .parameterType("params")
                        .build(),
                new ParameterBuilder()
                        .name("identifier")
                        .description("用户id")
                        .modelRef(new ModelRef("string"))
                        .parameterType("params")
                        .build()
        );
    }
}
